using System;
using System.Data;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using PCSComProduct.Costing.DS;

namespace PCSComProduct.Items.BO
{
	public class OperHourDetailBO //:  IOperHourDetailBO
	{
		public OperHourDetailBO()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		#region IOperHourDetailBO Members

		//**************************************************************************              
		///    <Description>
		///    Get the Cost information
		///    1.Cost Description
		///    2. and the order cost
		///    </Description>
		///    <Inputs>
		///       
		///    </Inputs>
		///    <Outputs>
		///       Button will be disable or enable
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       THIENHD
		///    </Authors>
		///    <History>
		///       15-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		//[AutoComplete(true)]
		public DataTable GetListOfCostDetail(int pintProductID, int pintCCNID)
		{
			try 
			{
				//1.Get the ITM_CostDescription
				ITM_CostDescriptionDS objITM_CostDescriptionDS = new ITM_CostDescriptionDS();
				DataTable dtCost_Description = objITM_CostDescriptionDS.GetHourCostDescription(pintCCNID);

				//2.Get the ITM_CostOperation
				ITM_CostOperationDS objITM_CostOperationDS = new ITM_CostOperationDS();
				DataTable dtCostOperation = objITM_CostOperationDS.GetHourCostOperation(pintProductID,pintCCNID);

				//3.Define the column name for this table
				const string COSTDESCRIPTION_FLD = "CostDescription";
				const string COMPONENTCOST_FLD = "ComponentHour";
				const string VALUEADDEDCOST_FLD = "ValueAddedHour";
				const string ITEMCOST_FLD = "OperationHour";


				//Create this table
				DataTable dtResult = new DataTable();
				dtResult.Columns.Add(COSTDESCRIPTION_FLD);
				dtResult.Columns.Add(COMPONENTCOST_FLD);
				dtResult.Columns.Add(VALUEADDEDCOST_FLD);
				dtResult.Columns.Add(ITEMCOST_FLD);
				DataRow drNewRow;

				//Add default 21 empty row
				for (int i=1 ; i<=4; i++)
				{
					drNewRow = dtResult.NewRow();
					dtResult.Rows.Add(drNewRow);
				}

				bool blnHaveData = false;

				//first add the Cost Description to the 4 rows
				if (dtCost_Description.Rows.Count > 0)
				{
					blnHaveData = true;

					dtResult.Rows[0][COSTDESCRIPTION_FLD] = dtCost_Description.Rows[0][ITM_CostDescriptionTable.MACHRUNHRSDESC_FLD];
					dtResult.Rows[1][COSTDESCRIPTION_FLD] = dtCost_Description.Rows[0][ITM_CostDescriptionTable.MACHSETUPHRSDESC_FLD];
					dtResult.Rows[2][COSTDESCRIPTION_FLD] = dtCost_Description.Rows[0][ITM_CostDescriptionTable.LABORRUNHRSDESC_FLD];
					dtResult.Rows[3][COSTDESCRIPTION_FLD] = dtCost_Description.Rows[0][ITM_CostDescriptionTable.LABORSETUPHRSDESC_FLD];
				}

				//add the component cost, valued added cost, item cost
				if (dtCostOperation.Rows.Count > 0) 
				{
					blnHaveData = true;

					//assign the Component Cost
					dtResult.Rows[0][COMPONENTCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.COMPONENTLABORRUNHOUR_FLD];
					dtResult.Rows[1][COMPONENTCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.COMPONENTLABORSETUPHOUR_FLD];
					dtResult.Rows[2][COMPONENTCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.COMPONENTMACHINERUNHOUR_FLD];
					dtResult.Rows[3][COMPONENTCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.COMPONENTMACHINESETUPHOUR_FLD];

					//assign the Value Added Hours
					dtResult.Rows[0][VALUEADDEDCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.VALUEADDEDLABORRUNHOUR_FLD];
					dtResult.Rows[1][VALUEADDEDCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.VALUEADDEDLABORSETUPHOUR_FLD];
					dtResult.Rows[2][VALUEADDEDCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.VALUEADDEDMACHINERUNHOUR_FLD];
					dtResult.Rows[3][VALUEADDEDCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.VALUEADDEDMACHINESETUPHOUR_FLD];

					//assign the operation hour
					dtResult.Rows[0][ITEMCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.OPERATIONLABORRUNHOUR_FLD];
					dtResult.Rows[1][ITEMCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.OPERATIONLABORSETUPHOUR_FLD];
					dtResult.Rows[2][ITEMCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.OPERATIONMACHINERUNHOUR_FLD];
					dtResult.Rows[3][ITEMCOST_FLD] = dtCostOperation.Rows[0][ITM_CostOperationTable.OPERATIONMACHINESETUPHOUR_FLD];
				}
				if (!blnHaveData)
				{
					dtResult.Rows.Clear();
				}
				
				
				return dtResult;
			}
			catch (PCSDBException ex) 
			{
				throw ex;
			}
			catch (Exception ex) 
			{
				throw ex;
			}
		}

		#endregion

		#region IObjectBO Members

		public void UpdateDataSet(DataSet dstData)
		{
			// TODO:  Add OperHourDetailBO.UpdateDataSet implementation
		}

		public void Update(object pObjectDetail)
		{
			// TODO:  Add OperHourDetailBO.Update implementation
		}

		public void Delete(object pObjectVO)
		{
			// TODO:  Add OperHourDetailBO.Delete implementation
		}

		public void Add(object pObjectDetail)
		{
			// TODO:  Add OperHourDetailBO.Add implementation
		}

		public object GetObjectVO(int pintID, string VOclass)
		{
			// TODO:  Add OperHourDetailBO.GetObjectVO implementation
			return null;
		}

		#endregion

	}

}
